import java.util.LinkedList;
import java.util.Stack;

public class Text {
    public boolean IsPopOrder(int[]pushV,int[]popV){
        Stack<Integer>stack=new Stack<>();
        int j=0;
        for(int i=0;i<pushV.length;i++){
            stack.push(pushV[i]);
            while(!stack.empty()&&j< popV.length&&popV[j]!=stack.peek()) {
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
    public static void main(String[] args) {
        LinkedList<Integer> linkedList=new LinkedList<>();
        linkedList.addLast(1);
        linkedList.addLast(2);
        linkedList.addLast(3);
        linkedList.addLast(4);
        linkedList.addLast(5);
        System.out.println(linkedList);
        //逆序打印链表
        //用递归的方式打印

    }
    public static void main3(String[] args) {
        //双向链表也可以有栈的功能
        LinkedList linkedList=new LinkedList<>();
        linkedList.push(12);
        linkedList.push(23);
        linkedList.push(34);
        linkedList.push(45);
        System.out.println(linkedList.peek());
        System.out.println(linkedList.pop());
        System.out.println(linkedList.peek());
        System.out.println(linkedList.pop());
        System.out.println(linkedList.peek());
        System.out.println(linkedList.pop());
        System.out.println(linkedList.peek());
        System.out.println(linkedList.pop());
        System.out.println(linkedList.pop());
    }
    public static void main2(String[] args) {
     Mystack mystack=new Mystack();
     mystack.push(12);
     mystack.push(23);
     mystack.push(34);
     mystack.push(45);


    }
    public static void main1(String[] args) {
        Stack<Integer> stack=new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        System.out.println(stack.pop());
        System.out.println(stack.peek());//是获取这个栈中的元素，不是让这个元素出去

    }
}
